import javax.swing.*;

/**
 * Created by админ on 26.06.14.
 */
public class List<E>
{
Node head;
    void add(E data)           //добавить спереди
    {
        Node a = new Node();
        a.x = data;

        if(head == null)
        {
            head = a;
        }
        else {
            a.next = head;
            head = a;
        }
    }
    void printList(final JTextField textField)        //вывод списка
    {String s = "";
        Node t = head;
        while (t != null)
        {
           s=s+t.x + " ";
            t = t.next;
        }
        textField.setText(s);
    }
    void delEl(E data)//удаление элемента
 {
    if(head == null)
    return;
    if (head.next==null)
    {
        if (head.x.equals(data))
        {head=null;
        return;}
    }
     if (head.x.equals(data))
      head=head.next;

     Node t=new Node();
     t = head;
     head=t;
     while (t.next != null) {
           if (t.next.x.equals(data)) {
                t.next = t.next.next;
                return;
                }
           t = t.next;
           }
 }
    void popEl()
    {
        if (head.next==null)
        {

            head=null;
            return;

        }
        head=head.next;
    }
}
